﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using VirtualPress.Tool.Framework;

namespace VirtualPress.Infrastructure.Entities.Repository
{
    [Table("T_Meeting")]
    public class T_Meeting : IEntity<T_Meeting>
    {
        [Key]
        [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Column(TypeName="nvarchar")]
        [StringLength(256)]
        public string Name { get; set; }

        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string Name_EN { get; set; }
        /// <summary>
        /// 期刊缩写
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(128)]
        public string ShortName { get; set; }
        /// <summary>
        /// 管理员账户
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string Admin { get; set; }
       
        /// <summary>
        /// 行业分类
        /// </summary>
        public int IndType { get; set; }
        /// <summary>
        /// 出版社_Id
        /// </summary>
        public int Press_Id { get; set; }
        /// <summary>
        /// 联系信息
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(1024)]
        public string ContactInfo { get; set; }
        [Column(TypeName = "varchar")]
        [StringLength(64)]
        public string Fax { get; set; }
        [Column(TypeName="nvarchar")]
        [StringLength(256)]
        public string ZBDW { get; set; }
        [Column(TypeName = "nvarchar")]
        [StringLength(256)]
        public string CBDW { get; set; }
        /// <summary>
        /// 会议规模
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(128)]
        public string HYGM { get; set; }
        [Column(TypeName="text")]
        public string ZGFW { get; set; }
        /// <summary>
        /// 联系邮箱
        /// </summary>
        public string Email { get; set; }
        /// <summary>
        /// 摘要
        /// </summary>
        [Column(TypeName = "text")]
        public string Abstract { get; set; }
        /// <summary>
        /// 会议详情
        /// </summary>
        [Column(TypeName="text")]
        public string About { get; set; }
        /// <summary>
        /// 征稿启事
        /// </summary>
        [Column(TypeName = "text")]
        public string CallForPaper { get; set; }
        /// <summary>
        /// 作者须知
        /// </summary>
        [Column(TypeName="text")]
        public string Attention { get; set; }
        /// <summary>
        /// 会议日期
        /// </summary>
        public DateTime StartDate { get; set; }
        /// <summary>
        /// 截稿日期
        /// </summary>
        public DateTime ArticleEndDate { get; set; }
        /// <summary>
        /// 会后旅游
        /// </summary>
        [Column(TypeName = "text")]
        public string Travel { get; set; }
        /// <summary>
        /// 日程安排
        /// </summary>
        [Column(TypeName = "text")]
        public string Schedule { get; set; }
        /// <summary>
        /// 状态
        /// </summary>
        public int Status { get; set; }
        [Column(TypeName = "nvarchar")]
        [StringLength(256)]
        public string Address { get; set; }
        /// <summary>
        /// 会议集信息
        /// </summary>
        [Column(TypeName = "text")]
        public string Catalog { get; set; }
        [Column(TypeName="bit")]
        public bool isActive { get; set; }
        /// <summary>
        /// 是否已经初始化
        /// </summary>
        [Column(TypeName="bit")]
        public bool isInstall { get; set; }
        /// <summary>
        /// 会议外链地址
        /// </summary>
        [Column(TypeName="varchar")]
        [StringLength(256)]
        public string Link { get; set; }
        /// <summary>
        /// 默认审回时间
        /// </summary>
        public int DefaultExamineDay { get; set; }
        public int ManuscriptPageSize { get; set; }
        /// <summary>
        /// 是否收取专审费
        /// </summary>
        [Column(TypeName = "bit")]
        public bool IsFeeForExpertExmaine { get; set; }
        public int PagePrice { get; set; }
        public int PricePerPrice { get; set; }
        /// <summary>
        /// 出版费
        /// </summary>
        public int PublicationPrice { get; set; }
        [Column(TypeName="nvarchar")]
        [StringLength(256)]
        public string Logo { get; set; }
        [Column(TypeName="text")]
        public string Css { get; set; }
        public int DownloadNumber { get; set; }
        public int VisitNumber { get; set; }

        [Column(TypeName="nvarchar")]
        [StringLength(256)]
        public string GroupName { get; set; }
        /// <summary>
        /// 组委会
        /// </summary>
        [Column(TypeName="text")]
        public string Committee { get; set; }
        /// <summary>
        /// 联系我们
        /// </summary>
        [Column(TypeName = "text")]
        public string AboutUs { get; set; }

        [Column(TypeName="nvarchar")]
        [StringLength(256)]
        public string Keyword { get; set; }
        [Column(TypeName = "nvarchar")]
        [StringLength(512)]
        public string Description { get; set; }

        public override T_Meeting Find(string key)
        {
            int id = key.ToInt32(0);
            return Find(c => c.Id == id);
        }

        public override T_Meeting Find(System.Linq.Expressions.Expression<Func<T_Meeting, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.Meeting.FirstOrDefault(where);
                if (item != null)
                {
                    this.Keyword = item.Keyword;
                    this.Description = item.Description;
                    this.Committee = item.Committee;
                    this.AboutUs = item.AboutUs;
                    this.DefaultExamineDay = item.DefaultExamineDay;
                    this.ManuscriptPageSize = item.ManuscriptPageSize;
                    this.IsFeeForExpertExmaine = item.IsFeeForExpertExmaine;
                    this.PagePrice = item.PagePrice;
                    this.PricePerPrice = item.PricePerPrice;
                    this.PublicationPrice = item.PublicationPrice;
                    this.Abstract = item.Abstract;
                    this.About = item.About;
                    this.Admin = item.Admin;
                    this.CBDW = item.CBDW;
                    this.ContactInfo = item.ContactInfo;
                    this.Email = item.Email;
                    this.Fax = item.Fax;
                    this.HYGM = item.HYGM;
                    this.Id = item.Id;
                    this.IndType = item.IndType;
                    this.isActive = item.isActive;
                    this.Link = item.Link;
                    this.Name = item.Name;
                    this.Name_EN = item.Name_EN;
                    this.Press_Id = item.Press_Id;
                    this.ShortName = item.ShortName;
                    this.ZBDW = item.ZBDW;
                    this.ZGFW = item.ZGFW;
                    this.Logo = item.Logo;
                    this.Css = item.Css;
                    this.DownloadNumber = item.DownloadNumber;
                    this.VisitNumber = item.VisitNumber;
                    this.CallForPaper = item.CallForPaper;
                    this.Attention = item.Attention;
                    this.StartDate = item.StartDate;
                    this.ArticleEndDate = item.ArticleEndDate;
                    this.Travel = item.Travel;
                    this.Schedule = item.Schedule;
                    this.Status = item.Status;
                    this.Address = item.Address;
                    this.Catalog = item.Catalog;
                    this.isInstall = item.isInstall;
                    this.GroupName = item.GroupName;
                    return this;
                }
                return null;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<T_Meeting, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.Meeting.Any(where);
            }
        }
    }
}
